/*---------------------------------------------------------------------------------------
功能：0.生成一个点类point;1.类内要包含二维坐标数值；
     2.通过该类实现点坐标的初始化；3.坐标修改；4. 坐标位置输出；
     5.然后基于该Point类设计一个友元函数 double distance(Point &A, Point &B), 实现计算两个点对象之间的直线距离
	 pow(a,b);//a的b次方

---------------------------------------------------------------------------------------*/

#include<iostream>
#include<Windows.h>
#include<cstdlib>
#include<cmath>
const int MAX = 5;
using namespace std;


class Point
{
private:
	
	int value;
	int wide;
	int length;
public:
	Point() 
	{
		value = 0;
		wide = 0;
		length = 0;
	}
	Point(int a, int b, int c)
	{
		value = a;
		wide = b;
		length = c;
	}
	Point(const Point& r)
	{
		this->value = r.value;
		this->wide = r.wide;
		this->length = r.length;
	}

	~Point()
	{
		cout << "The destructor was called !";
	}

	void GetPoint()
	{
		cout << "value=" << value << endl;
		cout << "wide=" << wide << endl;
		cout << "length=" << length << endl;
	}

	int GetValue(); //取值
	void SetValue(int,int,int); //改值
	void GetAdress(); //查找值对应的位置并输出
	friend double distance(Point &A, Point &B);


};
//友元函数
double distance(Point &A, Point &B)
{
	return sqrt(pow(abs((A.wide - B.wide))+1,2) + pow(abs((A.length-B.length))+1,2));
}
//改值函数
void Point::SetValue(int camp,int a,int b) //改值
{
	this->value = camp;
	this->wide = a;
	this->length = b;
}
int Point::GetValue() //输出值
{
	return value;
  
}
void Point::GetAdress() //查找值对应的位置并输出
{
	cout <<"location of("<<value<<"):"<<"(" << wide << "," << length << ")"<<endl;
}

void FindLocation(Point p[][MAX], int x, int y)
{
	int i=0,j=0,x1=0,x2=0,y1=0,y2=0;
	for ( i = 0;i < MAX;i++)
	{
		for ( j = 0;j < MAX;j++)
		{
			if (p[i][j].GetValue()==x)
			{
				x1 = i;
				x2 = j;
				p[i][j].GetAdress();
			}
			if (p[i][j].GetValue() == y)
			{
				y1 = i;
				y2 = j;
				p[i][j].GetAdress();
			}
		}
	}
	cout <<"The distance of the two numbers is "<< distance(p[x1][x2], p[y1][y2])<<endl;

}



//主函数

int main()
{
	Point points[MAX][MAX];
	{  //用于改值
		int camp = 0;
		for (int i = 0;i < MAX;i++)
		{
			cout << "Enter MAX integer numbers to initialize:";
			for (int j = 0;j < MAX;j++)
			{
				cin >> camp;
				points[i][j].SetValue(camp, i, j);
			}
		}

	}
	
	{
		int a, b;
	    cout << "Enter two numbers to calculate their distance:";
		cin >> a >> b;
		FindLocation(points, a, b);

	}


	system("pause");
	
	return 0;
}